package com.yafeed.trade.pojo.dto.industry;

import com.yafeed.trade.common.utils.IdGenerator;
import com.yafeed.trade.entity.industry.Industry;
import com.yafeed.trade.pojo.dto.stock.LeaderStockDto;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import org.springframework.beans.BeanUtils;

import java.io.Serializable;
import java.math.BigDecimal;

/**
 * @description: 新浪行业版块信息
 * @author: yanghj
 * @time: 2020-12-13 12:07
 */

@Setter
@Getter
@ToString
public class IndustryDto implements Serializable {

    private static final long serialVersionUID = 6140232953951213322L;

    /**
     * 主键
     */
    private Long industryId;

    /**
     * 行业名称
     */
    private String industryName;

    /**
     * 行业代码
     */
    private String industryCode;

    /**
     * 公司数量
     */
    private Integer companies;

    /**
     * 平均价格
     */
    private BigDecimal averagePrice;

    /**
     * 涨跌额
     */
    private BigDecimal changeAmount;

    /**
     * 涨跌幅（百分比）
     */
    private BigDecimal changeRange;

    /**
     * 成交量
     */
    private Long tradeVolume;

    /**
     * 成交额
     */

    private Long tradePrice;


    /**
     * 领涨股
     */
    private LeaderStockDto leaderStockDto;


    private static IndustryDto of() {
        IndustryDto industryDto = new IndustryDto();
        industryDto.setIndustryId(IdGenerator.getGuid());

        return industryDto;
    }


    public static IndustryDto of(String industryStr) {
        IndustryDto industryDto = of();
        String[] serNo = industryStr.split(",");

        industryDto.setIndustryCode(serNo[0]);
        industryDto.setIndustryName(serNo[1]);
        industryDto.setCompanies(Integer.parseInt(serNo[2]));
        industryDto.setAveragePrice(new BigDecimal(serNo[3]));
        industryDto.setChangeAmount(new BigDecimal(serNo[4]));
        industryDto.setChangeRange(new BigDecimal(serNo[5]));
        industryDto.setTradeVolume(Long.parseLong(serNo[6]));
        industryDto.setTradePrice(Long.parseLong(serNo[7]));


        LeaderStockDto stockDto = LeaderStockDto.of();
        stockDto.setIndustryId(industryDto.getIndustryId());
        stockDto.setIndustryCode(industryDto.getIndustryCode());
        stockDto.setStockCode(serNo[8]);
        stockDto.setChangeRange(new BigDecimal(serNo[9]));
        stockDto.setCurrentPrice(new BigDecimal(serNo[10]));
        stockDto.setChangeAmount(new BigDecimal(serNo[11]));
        stockDto.setStockName(serNo[12]);


        industryDto.setLeaderStockDto(stockDto);
        return industryDto;
    }


    public Industry toIndustry() {
        Industry industry = new Industry();
        BeanUtils.copyProperties(this, industry);
        return industry;
    }


}
